import 'package:flutter/material.dart';

///根布局构建器（MaterialApp为根布局）
typedef RootWidgetBuilder = Widget Function(BuildContext context, Size size);

class RootWidget extends StatelessWidget {
  final PreferredSizeWidget appBar;
  final RootWidgetBuilder builder;
  final Widget bottomNavigationBar;

  RootWidget(
      {this.appBar, @required this.builder, this.bottomNavigationBar, Key key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: this.appBar,
      body: RootContent(this.builder),
      bottomNavigationBar: this.bottomNavigationBar,
    );
  }
}

class RootContent extends StatelessWidget {
  final RootWidgetBuilder builder;

  RootContent(this.builder);

  @override
  Widget build(BuildContext context) {
    final Size _size = MediaQuery.of(context).size;
    return SingleChildScrollView(
      child: Container(
        width: _size.width,
        height: _size.height,
        child: this.builder(context, _size),
      ),
    );
  }
}
